package com.example.java.controller;

import com.example.java.entity.Banner;
import com.example.java.mapper.BannerMapper;
import com.example.java.utils.QiniuImageUtils;
import com.example.java.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerMapper bannerMapper;

    @Autowired
    private QiniuImageUtils qiniuImageUtils;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result bannerList() {
        List<Banner> bannerList = bannerMapper.selectList(null);
        for (Banner banner : bannerList) {
            banner.setPic(qiniuImageUtils.generatePrivateImageUrl(banner.getPic()));
        }
        return Result.ok().data("data", bannerList);


    }

}
